package com.xmuexp.e09.service;

import com.xmuexp.e09.dao.GoodsDao;
import org.springframework.stereotype.Service;
import com.xmuexp.e09.model.*;
import com.xmuexp.e09.dao.*;
import com.xmuexp.e09.util.*;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class GoodsService {

    @Autowired
    private GoodsDao goodsDao;
    public ReturnObject<VoObject> findById(Integer id) {
        GoodsPo queryObj = new GoodsPo();
        queryObj.setId(id);
        ReturnObject<VoObject> retGoods = null;
        ReturnObject<List<Goods>> returnObject = goodsDao.findGoods(queryObj);

        if (returnObject.getCode().equals(ResponseCode.OK)) {
            if (returnObject.getData().size() == 1) {
                retGoods = new ReturnObject<>(returnObject.getData().get(0));
            }else{
                retGoods = new ReturnObject<>(ResponseCode.RESOURCE_ID_NOTEXIST);
            }
        }else{
            retGoods = new ReturnObject<>(returnObject.getCode(), returnObject.getErrmsg());
        }
        return retGoods;
    }
}
